<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <LibrariesConfiguration>Release</LibrariesConfiguration>
    <InstallV8ForTests>false</InstallV8ForTests>
  </PropertyGroup>

  <Import Project="$(MSBuildThisFileDirectory)\Common\dir.sdkbuild.props" Condition="'$(UsingMicrosoftNETSdk)' == 'true'"  />
  <Import Project="$(MSBuildThisFileDirectory)\Common\dir.common.props" Condition="'$(UsingMicrosoftNETSdk)' != 'true'"  />

  <PropertyGroup>
    <RunningOnUnix Condition="('$(RunningOnUnix)' == '') And ('$(MSBuildRuntimeType)' == 'Core') And ('$(OS)'!='Windows_NT')">true</RunningOnUnix>
  </PropertyGroup>

  <!-- Common repo directories -->
  <PropertyGroup>
    <TestProjectDir>$(MSBuildThisFileDirectory)</TestProjectDir>
    <TestSourceDir>$([MSBuild]::NormalizePath('$(RepoRoot)/src/tests/'))</TestSourceDir>
  </PropertyGroup>

  <PropertyGroup>
    <AltJitArch>$(__AltJitArch)</AltJitArch>
    <EnableNativeSanitizers Condition="'$(__EnableNativeSanitizers)' != ''">$(__EnableNativeSanitizers)</EnableNativeSanitizers>
  </PropertyGroup>

  <!-- Output paths -->
  <PropertyGroup>
    <!-- When not using the SDK, we want to set this property here so
         that BuildVersionFile gets the correct value. -->
    <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == '' Or '$(UsingMicrosoftNETSdk)' != 'true'">$(ArtifactsDir)obj\</BaseIntermediateOutputPath>
    <IntermediateOutputPath Condition="'$(IntermediateOutputPath)' == ''">$(BaseIntermediateOutputPath)\$(TargetOS).$(TargetArchitecture).$(Configuration)</IntermediateOutputPath>
    <OutputPath Condition="'$(OutputPath)' == ''">$(BaseIntermediateOutputPath)\coreclr\$(TargetOS).$(TargetArchitecture).$(Configuration)</OutputPath>
  </PropertyGroup>

    <!-- Targeting Package paths -->
  <PropertyGroup>
    <TargetingPackPath Condition="'$(BaseTargetingPackPath)' == ''">$(ArtifactsDir)TargetingPack\</TargetingPackPath>
  </PropertyGroup>

  <PropertyGroup Condition="'$(BuildAllProjects)'=='true'">
    <!-- When we do a traversal build we get all packages up front, don't restore them again -->
    <RestorePackages>false</RestorePackages>
  </PropertyGroup>

  <!-- Which tests shall we build? Default: Priority 0 tests.
    At the command-line, the user can specify /p:CLRTestPriorityToBuild=666 (for example), and
    all tests with CLRTestPriority 666,..., 1 AND 0 will build.

    Consequently, specifying CLRTestPriorityToBuild=1 will build all tests with CLRTestPriority 1 and 0.

    CLRTestPriority = 0 will build only priority 0 cases.

    In other words, the CLRTestPriority cases of 0 are *essential* testcases. The higher the value,
    the less priority we give them.
   -->
  <PropertyGroup>
    <CLRTestPriorityToBuild>0</CLRTestPriorityToBuild>
    <CLRTestPriorityToBuild Condition="'$(__Priority)' != ''">$(__Priority)</CLRTestPriorityToBuild>

    <WindowsHost>$([MSBuild]::IsOSPlatform(Windows))</WindowsHost>

    <TargetsWindows>false</TargetsWindows>
    <TargetsWindows Condition="'$(TargetOS)' == 'windows'">true</TargetsWindows>

    <ScriptExt>.sh</ScriptExt>
    <ScriptExt Condition="$(WindowsHost)">.cmd</ScriptExt>

    <DotNetCli>"$(RepoRoot)\dotnet$(ScriptExt)"</DotNetCli>

    <XunitTestBinBase Condition="'$(XunitTestBinBase)' == ''">$(__TestBinDir)</XunitTestBinBase>
    <XunitTestBinBase>$([MSBuild]::NormalizeDirectory('$(XunitTestBinBase)/'))</XunitTestBinBase>
    <CORE_ROOT Condition="'$(CORE_ROOT)' == ''">$(XunitTestBinBase)Tests/Core_Root</CORE_ROOT>

    <TestBuildMode Condition="'$(__TestBuildMode)' != ''">$(__TestBuildMode)</TestBuildMode>
    <RuntimeFlavor Condition="'$(__RuntimeFlavor)' != ''">$(__RuntimeFlavor)</RuntimeFlavor>
    <RuntimeFlavor Condition="'$(RuntimeFlavor)' == ''">coreclr</RuntimeFlavor>

    <RestoreDefaultOptimizationDataPackage Condition="'$(RestoreDefaultOptimizationDataPackage)' == ''">false</RestoreDefaultOptimizationDataPackage>

    <UsePartialNGENOptimization Condition="'$(UsePartialNGENOptimization)' == ''">false</UsePartialNGENOptimization>

    <RunWithAndroid>false</RunWithAndroid>
    <RunWithAndroid Condition="'$(TargetOS)' == 'android'">true</RunWithAndroid>

    <RunWithiOS>false</RunWithiOS>
    <RunWithiOS Condition="'$(TargetOS)' == 'ios' or '$(TargetOS)' == 'iossimulator' or '$(TargetOS)' == 'tvos' or '$(TargetOS)' == 'tvossimulator' or '$(TargetOS)' == 'maccatalyst'">true</RunWithiOS>

    <MonoAot>false</MonoAot>
    <MonoAot Condition="'$(__MonoAot)' == '1'">true</MonoAot>
    <RuntimeVariant Condition="'$(__MonoAot)' == '1'">llvmaot</RuntimeVariant>

    <MonoFullAot>false</MonoFullAot>
    <MonoFullAot Condition="'$(__MonoFullAot)' == '1'">true</MonoFullAot>
    <RuntimeVariant Condition="'$(__MonoFullAot)' == '1'">llvmfullaot</RuntimeVariant>

    <MonoBinDir>$(__MonoBinDir)</MonoBinDir>
  </PropertyGroup>

  <!-- Setup Default symbol and optimization for Configuration -->
  <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <Optimize Condition="'$(Optimize)' == ''">false</Optimize>
    <DebugType Condition="'$(DebugType)' == ''">full</DebugType>
    <DefineConstants>$(DefineConstants);DEBUG;TRACE;XUNIT_PERF</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <Optimize Condition="'$(Optimize)' == ''">true</Optimize>
    <DebugType Condition="'$(DebugType)' == ''">pdbonly</DebugType>
    <DefineConstants>$(DefineConstants);TRACE;XUNIT_PERF</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Checked'">
    <Optimize Condition="'$(Optimize)' == ''">true</Optimize>
    <DebugType Condition="'$(DebugType)' == ''">full</DebugType>
    <DefineConstants>$(DefineConstants);DEBUG;TRACE;XUNIT_PERF</DefineConstants>
  </PropertyGroup>

  <!-- Setup the default output and intermediate paths -->
  <PropertyGroup>
    <SkipXunitDependencyCopying>true</SkipXunitDependencyCopying>
  </PropertyGroup>

  <!-- Disable some standard properties for building our projects -->
  <PropertyGroup>
    <NoExplicitReferenceToStdLib>true</NoExplicitReferenceToStdLib>
    <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
    <!-- Disable some C# warnings for the tests. -->
    <NoWarn>78,162,164,168,169,219,251,252,414,429,618,642,649,652,659,675,1691,1717,1718,3001,3002,3003,3005,3008,8981</NoWarn>
    <!--
      Disable xunit warnings that aren't relevant with our custom runner.
      xUnit1028: Use supported test return types. We support test methods that return int where 100 is passing and everything else is failure.
      xUnit1031: Don't use task blocking operations. Our runner doesn't set up a synchronization context, so we can use the blocking operations without issue.
      -->
    <NoWarn>$(NoWarn);xUnit1028;xUnit1031</NoWarn>
    <RunAnalyzers>false</RunAnalyzers>
    <EnableTrimAnalyzer>false</EnableTrimAnalyzer>
    <EnableAotAnalyzer>false</EnableAotAnalyzer>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <SkipSigning Condition="'$(CrossGen)' == 'true'">true</SkipSigning>
    <AssemblyKey>Test</AssemblyKey>
    <GenerateDependencyFile>false</GenerateDependencyFile>
    <GenerateRuntimeConfigurationFiles>false</GenerateRuntimeConfigurationFiles>
    <CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
    <UseAppHost>false</UseAppHost>
  </PropertyGroup>

  <!-- Set arch specific properties -->
  <PropertyGroup>
    <TargetBits>32</TargetBits>
    <TargetBits Condition="'$(TargetArchitecture)'=='x64'">64</TargetBits>
    <TargetBits Condition="'$(TargetArchitecture)'=='arm64'">64</TargetBits>
    <TargetBits Condition="'$(TargetArchitecture)'=='loongarch64'">64</TargetBits>
    <TargetBits Condition="'$(TargetArchitecture)'=='riscv64'">64</TargetBits>
  </PropertyGroup>

  <PropertyGroup>
    <Language Condition="'$(Language)' == '' and  '$(MSBuildProjectExtension)' == '.csproj'">C#</Language>
    <Language Condition="'$(Language)' == '' and  '$(MSBuildProjectExtension)' == '.fsproj'">F#</Language>
    <Language Condition="'$(Language)' == '' and  '$(MSBuildProjectExtension)' == '.ilproj'">IL</Language>
  </PropertyGroup>

  <!-- Don't reference the mscorlib facade -->
  <PropertyGroup>
    <ExcludeMscorlibFacade>true</ExcludeMscorlibFacade>
  </PropertyGroup>

  <!-- Don't append the RID to the output path for our test tree. Our test builds are already separated by RID
       and including the RID breaks some of our glob expressions in issues.targets -->
  <PropertyGroup>
    <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
  </PropertyGroup>

  <PropertyGroup>
    <!-- Specify the target framework of the common test dependency project.json. -->
    <NuGetTargetMoniker>$(NetCoreAppCurrentToolTargetFrameworkMoniker)</NuGetTargetMoniker>
    <NuGetTargetMonikerShort>$(NetCoreAppToolCurrent)</NuGetTargetMonikerShort>
  </PropertyGroup>

  <!-- Set Test Wrapper running host OS -->
  <PropertyGroup>
    <TestWrapperTargetsWindows>false</TestWrapperTargetsWindows>
    <TestWrapperTargetsWindows Condition=" ('$(TargetsWindows)' != '' And '$(TargetsWindows)' ) OR ('$(TargetOS)' == 'android' And '$(TargetArchitecture)' == 'arm64' )">true</TestWrapperTargetsWindows>
    <TestScriptExtension Condition="'$(TestWrapperTargetsWindows)' != 'true' ">sh</TestScriptExtension>
    <TestScriptExtension Condition="'$(TestWrapperTargetsWindows)' == 'true' ">cmd</TestScriptExtension>
  </PropertyGroup>

  <PropertyGroup>
    <!-- Scenario tests install this version of Microsoft.NetCore.App, then patch coreclr binaries via xcopy. At the moment it is
         updated manually whenever breaking changes require it to move forward, but it would be nice if we could update it automatically
         as we do with many of the package versions above -->
    <BaselineMicrosoftNetCoreAppPackageVersion>2.1.0-preview3-26416-01</BaselineMicrosoftNetCoreAppPackageVersion>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetOS)' == 'browser'">
    <CLRTestMSBuildArgs>/p:MSBuildEnableWorkloadResolver=false /p:Configuration=$(Configuration)</CLRTestMSBuildArgs>
  </PropertyGroup>

  <PropertyGroup Condition="'$(IsTestsCommonProject)' != 'true'">
    <BuildAsStandalone Condition="'$(BuildAsStandalone)' == ''">true</BuildAsStandalone>
    <OutputType Condition="$(BuildAsStandalone)">Exe</OutputType>
    <TestFramework>GeneratedRunner</TestFramework>

    <!-- Prevent project-specific NuGet props/targets from clashing with the ones we manually import below. -->
    <ImportProjectExtensionProps>false</ImportProjectExtensionProps>
    <ImportProjectExtensionTargets>false</ImportProjectExtensionTargets>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetOS)' == 'ios' or '$(TargetOS)' == 'tvos'">
    <EnableAggressiveTrimming Condition="'$(OutputType)' == 'Exe'">true</EnableAggressiveTrimming>
    <PublishTrimmed Condition="'$(OutputType)' == 'Exe'">true</PublishTrimmed>
    <SkipTestUtilitiesReference>true</SkipTestUtilitiesReference>
  </PropertyGroup>

  <PropertyGroup Condition="'$(RuntimeFlavor)' == 'coreclr' and '$(TargetsAppleMobile)' == 'true'">
    <_targetOS>$(TargetOS)</_targetOS>
    <UseNativeAOTRuntime>true</UseNativeAOTRuntime>
    <NativeLib>static</NativeLib>
    <CustomNativeMain>true</CustomNativeMain>
    <_IsApplePlatform Condition="'$(TargetsAppleMobile)' == 'true'">true</_IsApplePlatform>
    <_IsiOSLikePlatform Condition="'$(TargetsAppleMobile)' == 'true'">true</_IsiOSLikePlatform>
    <_SymbolPrefix Condition="'$(_IsApplePlatform)' == 'true'">_</_SymbolPrefix>
    <HybridGlobalization Condition="'$(_IsApplePlatform)' == 'true'">true</HybridGlobalization>
  </PropertyGroup>

  <Import Project="$(RepositoryEngineeringDir)testing\tests.props"  Condition="'$(IsTestsCommonProject)' != 'true'" />
  <Import Project="$(BaseOutputPath)\packages\Common\test_dependencies\test_dependencies\test_dependencies.*.props" Condition="'$(IsTestsCommonProject)' != 'true'" />
</Project>
